#! /bin/bash

numbers=( 1 6 10 12 20 24 40 48 )
PPU_NAME=pi_test
SLAVE_NAME=pi_slave
MASTER_NAME=pi_master
GRAIN=0.00001

create_ppu_code(){
	N_PROCS=$1;
	DIR=${PPU_NAME}_${N_PROCS};
	TEMPLATE=${PPU_NAME}.template;
	MASTER_CODE=${MASTER_NAME}_$1
	SLAVE_CODE=${SLAVE_NAME}_$1
	mkdir $DIR;
	cd $TEMPLATE/; cp Makefile *.cpp *.h ../$DIR;cd ..;
	echo "#define N $N_PROCS
#define GRAIN $GRAIN
#define MASTER_CODE  \"$MASTER_CODE\"
#define SLAVE_CODE \"$SLAVE_CODE\"" > $DIR/config.h
	touch $DIR/$DIR.name
}


create_spe_master(){
	cd tasks
	N_PROCS=$1
	TEMPLATE=${MASTER_NAME}.template
	DIR=${MASTER_NAME}_$1
	mkdir ${DIR}
	cd $TEMPLATE/; cp Makefile *.c *.h ../$DIR;cd ..;
	touch $DIR/$DIR.name	
	echo "#define N $N_PROCS
#define GRAIN $GRAIN" > $DIR/config.h
	cd ..
}

create_spe_slave(){
	cd tasks
	N_PROCS=$1
	TEMPLATE=${SLAVE_NAME}.template
	DIR=${SLAVE_NAME}_$1
	mkdir ${DIR}
	cd $TEMPLATE/; cp Makefile *.c *.h ../$DIR;cd ..;
	touch $DIR/$DIR.name	
	cd ..
}



delete(){
	SLAVE_DIR=tasks/${SLAVE_NAME}_$1
	MASTER_DIR=tasks/${MASTER_NAME}_$1
	PPU_DIR=${PPU_NAME}_$1;
	rm -fr $PPU_DIR
	rm -fr $SLAVE_DIR
	rm -fr $MASTER_DIR
}


for i in ${numbers[@]};
do
	if [ $1 == "clean" ]
		then
			delete $i
	elif [ $1 == "create" ]
		then
			create_ppu_code $i;
			create_spe_master $i;
			create_spe_slave $i;
	fi;
done;



